package gov.nist.ssd.swqb.gui.components;

import gov.nist.ssd.swqb.listeners.SearchNewResultListener;
import gov.nist.ssd.swqb.core.Display;
import gov.nist.ssd.swqb.events.NewSearchEvent;
import gov.nist.ssd.swqb.listeners.NewSearchListener;
import gov.nist.ssd.swqb.listeners.SearchResultListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.List;
import javax.swing.JTextField;

/**
 *
 * @author Benjamin Herbomez <benjamin.herbomez@esial.com>
 */
public class SearchComponent extends JTextField {

    private Display display = null;
    private List<EventListener> listeners = new ArrayList<EventListener>();

    public SearchComponent() {

        this.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                for (EventListener l : listeners) {
                    if (l instanceof NewSearchListener) {
                        ((NewSearchListener) l).newSearch(new NewSearchEvent(this,getText()));
                    }
                }
            }
        });
    }

    public void addSearchResultListener(SearchResultListener l) {
        this.listeners.add(l);
    }

    public void removeSearchResultListener(SearchResultListener l) {
        this.listeners.remove(l);
    }

    public void addSearchNewResultListener(SearchNewResultListener l) {
        this.listeners.add(l);
    }

    public void removeSearchNewResultListener(SearchNewResultListener l) {
        this.listeners.remove(l);
    }

    public void addNewSearchListener(NewSearchListener l) {
        this.listeners.add(l);
    }

    public void removeNewSearchListener(NewSearchListener l) {
        this.listeners.remove(l);
    }
}
